home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT18.ZIP / TUT18.TXT < prev   
Text File  |  1995-02-21  |  12KB  |  344 lines

  1.                    ╒═══════════════════════════════╕
  2.                    │         W E L C O M E         │
  3.                    │  To the VGA Trainer Program   │ │
  4.                    │              By               │ │
  5.                    │      DENTHOR of ASPHYXIA      │ │ │
  6.                    ╘═══════════════════════════════╛ │ │
  7.                      ────────────────────────────────┘ │
  8.                        ────────────────────────────────┘
  9.  
  10.                            --==[ PART 18 ]==--
  11.  
  12.  
  13.  
  14. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  15. ■ Introduction
  16.  
  17. Welcome back! I know, I know, you all all shocked that this tut is out so
  18. soon after the last one, but the reason for this is that I want to have Tut
  19. 20 out by the time PCGPE ][ is released. I probably won't get that far, but
  20. I'll try! ;)
  21.  
  22. This tut is on file packing, and putting everything into one executeable
  23. file. For tut 19, I am thinking of doing a bit more on explaining
  24. assembler, and perhaps demonstrating with a fire effect or something.
  25.  
  26. My mailserver is back up, thanks to Nobody (that's his handle). You write
  27. to denthor@beastie.cs.und.ac.za with the subject line request-list. The
  28. mailserver checks each incoming letter for this subject line, and if it
  29. finds one of the specific strings, it mails you back a certain file. I
  30. never get to see these messages! If you want to mail me personally, give
  31. your message a unique subject name! Anyway, you can request all the tuts
  32. through this mailserver.
  33.  
  34. I hope you are all subscribed to the Demuan List! If not, ftp it off
  35. ftp.eng.ufl.edu every sunday. I am writing a "humor" column there until
  36. someone can figure out something else I could write ;-).
  37.  
  38. Pipsy wants mail! She is at cowan@beastie.cs.und.ac.za and wants to chat :)
  39. Go on, mail her. The co-founder of ctrl-alt-del, she is also a good
  40. graphics coder.
  41.  
  42.  
  43. If you would like to contact me, or the team, there are many ways you
  44. can do it : 1) Write a message to Grant Smith/Denthor/Asphyxia in private mail
  45.                   on the ASPHYXIA BBS.
  46.             2) Write to :  Grant Smith
  47.                            P.O.Box 270 Kloof
  48.                            3640
  49.                            Natal
  50.                            South Africa
  51.             3) Call me (Grant Smith) at (031) 73 2129 (leave a message if you
  52.                   call during varsity). Call +27-31-73-2129 if you call
  53.                   from outside South Africa. (It's YOUR phone bill ;-))
  54.             4) Write to denthor@beastie.cs.und.ac.za in E-Mail.
  55.             5) Write to asphyxia@beastie.cs.und.ac.za to get to all of
  56.                us at once.
  57.  
  58. NB : If you are a representative of a company or BBS, and want ASPHYXIA
  59.        to do you a demo, leave mail to me; we can discuss it.
  60. NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling
  61.         quite lonely and want to meet/help out/exchange code with other demo
  62.         groups. What do you have to lose? Leave a message here and we can work
  63.         out how to transfer it. We really want to hear from you!
  64.  
  65. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  66. ■ Loading a PCX file
  67.  
  68. This is actually quite easy. The PCX file is divided into three sections,
  69. mainly a 128 byte header, a data section, and a 768 byte pallette.
  70.  
  71. You can usually ignore the 128 byte header, but here it is :
  72.  
  73. 0  Manufacturer     10 = ZSoft .PCX file
  74. 1  Version
  75. 2  Encoding
  76. 3  Bits Per Pixel
  77. 4  XMin, Ymin, XMax, YMax  (2 bytes each)
  78. 12 Horizontal Resolution (2 bytes)
  79. 14 Verticle Resolution (2 bytes)
  80. 16 Color pallette setting (48 bytes)
  81. 64 Reserved
  82. 65 Number of color planes
  83. 66 Bytes per line (2 bytes)
  84. 68 1 = Color    2 = Grayscale  (2 bytes)
  85. 70 Blank (58 bytes)
  86.  
  87. That makes 128 bytes.
  88.  
  89. The pallette file, which is 768 bytes, is situated at the very end of the
  90. PCX file. The 769'th byte back should be the decimal 12, which indicates
  91. that a VGA color pallette is to follow.
  92.  
  93. There is one thing that we have to do to get the pallette correct in VGA ...
  94. the PCX pallette values for R,G,B are 0 to 255 respectively. To convert this
  95. to our standard (VGA) pallette, we must divide the R,G,B values by 4, to get
  96. them into a range of 0 to 63.
  97.  
  98. Actually decoding the image is very simple. Starting after the 128 byte
  99. header, we read a byte.
  100.  
  101. If the top two bits of this byte are not set, we dump the value to the screen.
  102.  
  103. We check bits as follows :
  104.  
  105. if ((temp and $c0) = $c0) then ...(bits are set)... else ...(bits are not set)
  106.  
  107. C0 in hex = 11000000 in binary = 192 in decimal
  108.  
  109. Let's look at that more closely...
  110.  
  111.   temp  and  c0h
  112.   temp  and  11000000b
  113.  
  114. That means, when represented in bit format, both corresponding bits have
  115. to be set to one for the result to be one.
  116.  
  117. 0 and 0 = 0     1 and 0 = 0    0 and 1 = 0    1 and 1 = 1
  118.  
  119. In the above case then, both of the top two bits of temp have to be set for
  120. the result to equal 11000000b. If it does not equal that, the top two bits
  121. are not both set, and we can put the pixel.
  122.  
  123. So
  124.  
  125.   if ((temp and $c0) = $c0) then BEGIN
  126.   END else BEGIN
  127.     putpixel (screenpos,0,temp,vga);
  128.     inc (screenpos);
  129.   END;
  130.  
  131. If the top two bits _are_ set, things change. The bottom six bits become
  132. a loop counter, which the next byte is repeated.
  133.  
  134.   if ((temp and $c0) = $c0) then BEGIN
  135. {    Read in next byte, temp2 here.}
  136.     for loop1:=1 to (temp and $3f) do BEGIN
  137.       putpixel (screenpos,0,temp2,vga);
  138.       inc (screenpos);
  139.     END;
  140.   END else BEGIN
  141.     putpixel (screenpos,0,temp,vga);
  142.     inc (screenpos);
  143.   END;
  144.  
  145. There is our PCX loader. You will note that by and'ing temp by $3f, I am
  146. and'ing it by 00111111b ... in other words, clearing the top two bits.
  147.  
  148. The sample program has the above in assembler, but it is the same procedure...
  149. and you can read tut 19 for more info on how to code in assembler.
  150.  
  151. In the sample I assume that the pic is 320x200, with a maximum size of 66432
  152. bytes.
  153.  
  154.  
  155. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  156. ■  File packing
  157.  
  158. The question is simple .. how do I get all my files into one executeable?
  159. Having many small data files can start to look unprofessional.
  160.  
  161. An easy way to have one .exe and one .dat file when dealing with many
  162. cel's etc. is easy .... you would alter your load procedure, which looks
  163. as follows :
  164.  
  165. VAR temp : Array [1..5,1..256] of byte;
  166. Procedure Init;
  167. BEGIN
  168.   loadcel ('pic1.cel',temp[1]);
  169.   loadcel ('pic2.cel',temp[2]);
  170.   loadcel ('pic3.cel',temp[3]);
  171.   loadcel ('pic4.cel',temp[4]);
  172.   loadcel ('pic5.cel',temp[5]);
  173. END;
  174.  
  175. For one complile you would do this :
  176.  
  177. VAR temp : Array [1..5,1..256] of byte;
  178. Procedure Init;
  179. VAR f:File;
  180. BEGIN
  181.   loadcel ('pic1.cel',temp[1]);
  182.   loadcel ('pic2.cel',temp[2]);
  183.   loadcel ('pic3.cel',temp[3]);
  184.   loadcel ('pic4.cel',temp[4]);
  185.   loadcel ('pic5.cel',temp[5]);
  186.   assign (f,'pic.dat');
  187.   rewrite (f,1);
  188.   blockwrite (f,temp,sizeof(temp));
  189.   close (f);
  190. END;
  191.  
  192. From then on, you would do :
  193.  
  194. VAR temp : Array [1..5,1..256] of byte;
  195. Procedure Init;
  196. VAR f:File;
  197. BEGIN
  198.   assign (f,'pic.dat');
  199.   reset (f,1);
  200.   blockread (f,temp,sizeof(temp));
  201.   close (f);
  202. END;
  203.  
  204. This means that instead of five data files, you now have one! You have also
  205. stripped the 800 byte cel header too :) ... note that this will work for any
  206. form of data, not just cel files.
  207.  
  208. The next logical step is to include this data in the .exe file, but the
  209. question is how?  In an earlier tutorial, I converted my data file to
  210. constants and placed it inside my main program. This is not good mainly
  211. because of space restrictions ... you can only have so many constants, and
  212. what if your data file is two megs big?
  213.  
  214. Attached with this tutorial is a solution. I have written a program that
  215. combines your data files with your executeable file, no matter how big
  216. the data is. The only thing you have to worry about is a small change in
  217. your data loading methods. Lets find out what.
  218.  
  219.  
  220. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  221. ■  Using the file packer
  222.  
  223. Normally you would load your data as follows :
  224.  
  225. Procedure Init;
  226. BEGIN
  227.   loadcel ('bob.bob',temp);
  228.   loadpcx ('den.pcx',VGA);        { Load a PCX file }
  229.   loaddat ('data.dat',lookup);    { Load raw data into lookup }
  230. END;
  231.  
  232. Easy, hey? Now, using the file packer, you would change this to :
  233.  
  234. USES fpack;
  235. Procedure Init;
  236. BEGIN
  237.   total := 3;
  238.   infodat[1] := 'bob.bob';
  239.   infodat[2] := 'den.pcx';
  240.   infodat[3] := 'data.dat';
  241.   loadcel (1,temp);
  242.   loadpcx (2,VGA);
  243.   loaddat (3,lookup);
  244. END;
  245.  
  246. Not too difficult? Now, this is still using the normal data files on your
  247. hard drive. You would then run PACK.EXE, select the program's .exe as the
  248. base, then select "bob.bob", "den.pcx" and "data.dat", in order (1, 2, 3).
  249. Hit "c" to contine, and it will combine the files. Your programs .exe file
  250. will be able to run independantly of the separate data files on disk,
  251. because the data files are imbedded with the .exe.
  252.  
  253. Let us take a closer look at the load procedures. Normally a load procedure
  254. would look as follows :
  255.  
  256. Procedure LoadData (name:string; p:pointer);
  257. VAR f:file;
  258. BEGIN
  259.   assign (f,name);
  260.   reset (f,1);
  261.   blockread (f,p^,filesize(f);
  262.   close (f);
  263. END;
  264.  
  265. In FPack.pas, we do the following :
  266.  
  267. Function LoadData (num:integer; p:pointer):Boolean;
  268. VAR f:file;
  269. BEGIN
  270.   If pack then BEGIN
  271.     assign (f,paramstr(0));
  272.     reset (f,1);
  273.     seek (f,infopos[num]);
  274.     blockread (f, p^, infopos[num+1]-infopos[num]);
  275.     close (f);
  276.   END else BEGIN
  277.     assign (f,infodat[num]);
  278.     reset (f,1);
  279.     blockread (f, p^, filesize (f));
  280.     close (f);
  281.   END;
  282. END;
  283.  
  284. As you can see, we just have two special cases depending on weather or not
  285. the .exe file has been packed yet.
  286.  
  287. NOTE : After you have packed the file, you CAN NOT pklite it. You can
  288.        however pklite the .exe _before_ you run pack.exe ... in other
  289.        words, you can not use pklite to try pack your data files.
  290.  
  291. PACK.EXE does have a limitation ... you can only pack 24 data files together.
  292. If you would like it to do more, mail me ... It should be easy to increase the
  293. number.
  294.  
  295. In the sample program, FINAL.EXE is the same as temp.pas, except it has
  296. it's PCX embedded inside it. I ran pack2.exe, selected final.exe and
  297. eye.pcx, hit "C", and there it was. You will notice that eye.pcx is not
  298. included in the directory ... it is now part of the exe!
  299.  
  300. eye.pcx was draw by Gary Morton of iCANDi Design. The other pcx is an old
  301. one draw by Fubar.
  302.  
  303.  
  304. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  305. ■  In closing
  306.  
  307. Well, that's about it for this trainer... next one (as I have mentioned
  308. twice already ;) will be on assembler, with a flame routine thrown in.
  309.  
  310. Any good html programmers out there? My web page really needs help ;-)
  311.  
  312. As soon as I figure out how, I will also be creating a mailing list, in
  313. which people with internet addresses will be able to get all new trainers
  314. dilivered directly into their mailbox's. I hope to announce something in
  315. tut 20.
  316.  
  317. This tut has been a bit of a departure from normal tuts ... aside from the
  318. PCX loading routines, the rest has been "non programming" oriented ...
  319. don't worry, next weeks one will be back to normal.
  320.  
  321.  
  322. Byeeeee....
  323.   - Denthor
  324.  
  325. The following are official ASPHYXIA distribution sites :
  326.  
  327. ╔══════════════════════════╦════════════════╦═════╗
  328. ║BBS Name                  ║Telephone No.   ║Open ║
  329. ╠══════════════════════════╬════════════════╬═════╣
  330. ║ASPHYXIA BBS #1           ║+27-31-765-5312 ║ALL  ║ *Moving*
  331. ║ASPHYXIA BBS #2           ║+27-31-765-6293 ║ALL  ║ *Moving*
  332. ║C-Spam BBS                ║410-531-5886    ║ALL  ║
  333. ║POP!                      ║+27-12-661-1257 ║ALL  ║
  334. ║Soul Asylum               ║+358-0-5055041  ║ALL  ║
  335. ║Wasted Image              ║407-838-4525    ║ALL  ║
  336. ║Reckless Life             ║351-01-716 67 58║ALL  ║
  337. ║Mach 5 BBS                ║+1 319-355-7336 ║ALL  ║
  338. ║House of Horror           ║+1 513-734-6470 ║ALL  ║
  339. ║Zero Level                ║+39 6-810-9934  ║ALL  ║
  340. ╚══════════════════════════╩════════════════╩═════╝
  341.  
  342. Leave me mail if you want to become an official Asphyxia BBS
  343. distribution site.
  344.